package edu.intec.matsab.persistence;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import org.hibernate.validator.Length;
import org.hibernate.validator.NotEmpty;
import org.hibernate.validator.Pattern;

/**
 *
 * @author Sabrina
 */
@Entity
@Table(name = "Carrera")
@NamedQueries({@NamedQuery(name = "Carrera.findByIdCarrera", query = "SELECT c FROM Carrera c WHERE c.idCarrera = :idCarrera"),
    @NamedQuery(name = "Carrera.findByNombre", query = "SELECT c FROM Carrera c WHERE c.nombre = :nombre"),
    @NamedQuery(name = "Carrera.AllCarreras", query = "SELECT c FROM Carrera c")
})
public class Carrera implements Serializable {

    private static final long serialVersionUID = 1L;
    
    @NotEmpty(message = "Este campo es requerido")
    @Pattern(regex = "[a-zA-Z]+", message = "Este campo solo debe contener letras a-z/A-Z")
    @Length(min = 3, max = 3, message = "Este campo tiene un maximo de 3 caracteres")
    @Id
    @Basic(optional = false)
    @Column(name = "idCarrera")
    private String idCarrera;
    
    @NotEmpty( message="Este campo es requerido")
    @Pattern(regex = "[a-zA-Z0-9 ]+", message = "Este campo solo puede contener letras a-z/A-Z y numeros 0-9")
    @Length(min = 1, max = 50, message="Este campo tiene un maximo de 50 caracteres")
    @Basic(optional = false)
    @Column(name = "nombre")
    private String nombre;
    @JoinColumn(name = "idCarrera", referencedColumnName = "idCarrera")
    @OneToMany
    private Collection<Pensum> pensumCollection;

    public Carrera() {
    }

    public Carrera(String idCarrera) {
        this.idCarrera = idCarrera;
    }

    public Carrera(String idCarrera, String nombre) {
        this.idCarrera = idCarrera;
        this.nombre = nombre;
    }

    public String getIdCarrera() {
        return idCarrera;
    }

    public void setIdCarrera(String idCarrera) {
        this.idCarrera = idCarrera;
    }

    public String getNombre() {
        return nombre;
    }

    public void setNombre(String nombre) {
        this.nombre = nombre;
    }

    public Collection<Pensum> getPensumCollection() {
        return pensumCollection;
    }

    public void setPensumCollection(Collection<Pensum> pensumCollection) {
        this.pensumCollection = pensumCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idCarrera != null ? idCarrera.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Carrera)) {
            return false;
        }
        Carrera other = (Carrera) object;
        if ((this.idCarrera == null && other.idCarrera != null) || (this.idCarrera != null && !this.idCarrera.equals(other.idCarrera))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "edu.intec.matsab.persistence.Carrera[idCarrera=" + idCarrera + "]";
    }
}
